﻿@model DHQGHN.PM2.Models.Online.ThuongTru2Model
<style>
    .ui-tooltip, .arrow:after {
        background: #FAFAD2;
    }

    .ui-tooltip {
        color: black;
        font-size: 12px;
    }

    .arrow {
        width: 70px;
        height: 16px;
        overflow: hidden;
        position: absolute;
        left: 50%;
        margin-left: -35px;
        bottom: -16px;
    }

        .arrow.top {
            top: -16px;
            bottom: auto;
        }

        .arrow.left {
            left: 20%;
        }

        .arrow:after {
            content: "";
            position: absolute;
            left: 20px;
            top: -20px;
            width: 25px;
            height: 25px;
            box-shadow: 6px 5px 9px -9px black;
            -webkit-transform: rotate(45deg);
            -ms-transform: rotate(45deg);
            transform: rotate(45deg);
        }

        .arrow.top:after {
            bottom: -20px;
            top: auto;
        }
</style>
<script>
     @functions{
         public string GetAntiForgeryToken()
         {
             string cookieToken, formToken;
             AntiForgery.GetTokens(null, out cookieToken, out formToken);
             return cookieToken + "," + formToken;
         }
     };
    jQuery(function ($) {
        $("#divLoading").show();
        Tooltip();
        $("#btnNext").attr("disabled", "disabled");
        $("#btnBack").attr("disabled", "disabled");
        Checkngay("DAYAR");
        Checkthang("MONTHAR");
        Checknam("YEARAR");
        codear = $("#CODEAR").val();
        tinhar = $("#CODEAR").val().substring(0, 2);
        huyenar = $("#CODEAR").val().substring(0, 5);
        if (codear != "") {
            $("#TINH").val(tinhar);
        }
        if ($("#TINH").val() != "-1") {
            $.ajax({
                type: 'POST',
                url: '@Url.Action("GetAdministrativeUnit1")', 
                headers: {
                    'VerificationToken': '@GetAntiForgeryToken()'
                },
                dataType: 'json',

                data: {
                    code: $("#TINH").val(),
                    level: '2'
                },
                success: function (states) {
                    $("#HUYEN").append('<option value="' + '-1' + '">' +
                 '-- Chọn Huyện --' + '</option>');
                    $.each(states, function (i, state) {
                        $("#HUYEN").append('<option value="' + state.Value + '">' +
                             state.Text + '</option>');
                    });

                },
                complete: function () {
                    $("#HUYEN").val(huyenar);
                    $("#XA").empty();
                    $("#XA").append('<option value="' + '-1' + '">' +
                        '-- Chọn Xã --' + '</option>');
                    $.ajax({
                        type: 'POST',
                        url: '@Url.Action("GetAdministrativeUnit1")', 
                        headers: {
                            'VerificationToken': '@GetAntiForgeryToken()'
                        },
                        dataType: 'json',

                        data: {
                            code: $("#HUYEN").val(),
                            level: '3'
                        },
                        success: function (states) {
                            $.each(states, function (i, state) {
                                $("#XA").append('<option value="' + state.Value + '">' +
                                    state.Text + '</option>');
                            });

                        },
                        complete: function () {
                            $("#XA").val(codear);
                            Check();
                        },
                        error: function (ex) {
                            alert('Failed to retrieve states.' + ex);
                        }
                    });
                },
                error: function (ex) {
                    alert('Failed to retrieve states.' + ex);
                }
            });
        } else {
            $("#HUYEN").append('<option value="' + '-1' + '">' +
                 '-- Chọn Huyện --' + '</option>');
            $("#XA").append('<option value="' + '-1' + '">' +
                 '-- Chọn Xã --' + '</option>');
        }
        $("#TINH").change(function () {
            $("#divLoading").show();
            $("#HUYEN").empty();
            $("#XA").empty();
            $("#HUYEN").append('<option value="' + '-1' + '">' +
                 '-- Chọn Huyện --' + '</option>');
            $("#XA").append('<option value="' + '-1' + '">' +
                 '-- Chọn Xã --' + '</option>');
            $.ajax({
                type: 'POST',
                url: '@Url.Action("GetAdministrativeUnit1")',
                headers: {
                    'VerificationToken': '@GetAntiForgeryToken()'
                },
                dataType: 'json',

                data: {
                    code: $("#TINH").val(),
                    level: '2'
                },
                success: function (states) {
                    $.each(states, function (i, state) {
                        $("#HUYEN").append('<option value="' + state.Value + '">' +
                             state.Text + '</option>');
                    });

                },
                complete: function (states) {
                    $("#divLoading").hide();
                },
                error: function (ex) {
                    alert('Failed to retrieve states.' + ex);
                }
            });
            return false;
        })
        $("#HUYEN").change(function () {
            $("#divLoading").show();
            $("#XA").empty();
            $("#XA").append('<option value="' + '-1' + '">' +
                '-- Chọn Xã --' + '</option>');
            $.ajax({
                type: 'POST',
                url: '@Url.Action("GetAdministrativeUnit1")', 
                headers: {
                    'VerificationToken': '@GetAntiForgeryToken()'
                },
                dataType: 'json',

                data: {
                    code: $("#HUYEN").val(),
                    level: '3'
                },
                success: function (states) {
                    $.each(states, function (i, state) {
                        $("#XA").append('<option value="' + state.Value + '">' +
                             state.Text + '</option>');

                    });

                },
                complete: function () {
                    $("#divLoading").hide();
                },
                error: function (ex) {
                    alert('Failed to retrieve states.' + ex);
                }
            });
            return false;
        });
    });

    $.ajax({
        url: '@Url.Action("GetAllByListName")',
        dataType: 'json',
        headers: {
            'VerificationToken': '@GetAntiForgeryToken()'
        },
        method: 'GET',
        data: { 'tablename': 'RELATION' },
        success: function (data, textStatus, jqXHR) {
            $.each(data, function (i, item) {
                $(".RST_BOOK_RELATION_ID").append('<input type="radio" name="optradio" value="' + item.CodeID + '">' +
                     item.Name + '</input><br \>');

            });
            $("input[name=optradio][value=" + @Model.RST_BOOK_RELATION_ID + "]").attr('checked', 'checked');
        },
        complete: function () {
            Check();
        }


    });
    $.ajax({
        url: '@Url.Action("GetAllByListName")',
        dataType: 'json',
        headers: {
            'VerificationToken': '@GetAntiForgeryToken()'
        },
        method: 'GET',
        data: { 'tablename': 'RELIGION' },
        success: function (data, textStatus, jqXHR) {
            $(".RELIGION_ID").append('<option value="">' +
          '-- Chọn Tôn giáo --' + '</option>');
            $.each(data, function (i, item) {
                $(".RELIGION_ID").append('<option value="' + item.CodeID + '">' +
                     item.Name + '</option>');
            });
            $(".RELIGION_ID").val("@Model.RELIGION_ID");
        },
        complete: function () {
            Check();
        }


    });

    function ClickButton(Next) {
        $("#divLoading").show();
        var ngayar = $("#DAYAR").val();
        var thangar = $("#MONTHAR").val();
        var namar = $("#YEARAR").val();
        xa = $("#XA").val();
        if (xa == "-1") {
            xa = "";
        }
        var dataSend = {
            'HOUSEHOLD_ID': $("#HOUSEHOLD_ID").val(),
            'RESIDENT_ID': $("#RESIDENT_ID").val(),
            'RST_BOOK_RELATION_ID': $("input[name='optradio']:checked").val(),
            'ARRIVE_DATE': namar + thangar + ngayar,
            'POBA_ADM_UNIT_ID': xa,
            'RELIGION_ID': $(".RELIGION_ID").val(),
            'NEXT': Next,

        };
        var jqXHR = $.ajax({
            url: '@Url.Action("ThuongTru2","Online")',
            dataType: 'html',
            headers: {
                'VerificationToken': '@GetAntiForgeryToken()'
            },
            method: 'post',
            cache: false,
            data: dataSend,
            success: function myfunctionSuccess(data, textStatus, jqXHR) {
                if (Next == "2") {
                    $('#formLogin').html(data);
                }
                else {
                    $('#loadPartial').html(data);
                }
            },
            complete: function (jqXHR, textStatus) {
                $("#divLoading").hide();
                $("#btnNext").removeAttr("disabled");
                $("#btnBack").removeAttr("disabled");
            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert('Có lỗi xảy ra trong quá trình lưu thông tin: ' + errorThrown);
            },

        });
    }
    function Check() {
        var RELIGION_ID1 = $(".RELIGION_ID").val();
        var RELIGION_ID2 = $("#RST_BOOK_RELATION_ID").val();
        var radiobutton = $("input[name='optradio']:checked").val();
        var NP_ADM_UNIT_ID = $("#XA").val();
        if (NP_ADM_UNIT_ID == "-1") {
            NP_ADM_UNIT_ID = "";
        }
        var coun = $("#RELIGION_ID").val();
        if (RELIGION_ID2 == "") {
            RELIGION_ID2 = undefined;
        }
        if (RELIGION_ID1 == coun && NP_ADM_UNIT_ID == codear && radiobutton == RELIGION_ID2) {
            $("#divLoading").hide();
            $("#btnNext").removeAttr("disabled");
            $("#btnBack").removeAttr("disabled");
        }
        else {
            $("#divLoading").show();
            $("#btnNext").attr("disabled", "disabled");
            $("#btnBack").attr("disabled", "disabled");
        }

    };
    $("#btnNext").click(function (event, giatri) {
        if (checkhtml()) {
            alert("Dữ liệu nhập không được có ký tự '<' ở đầu.");
        } else {
            if (giatri != null) {
                ClickButton(giatri);
            }
            else {
                if (Checkdatetime("DAYAR", "MONTHAR", "YEARAR") == 0) {
                    ClickButton(1);
                }
            }
        }
    });
    $("#btnBack").click(function () {
        if (checkhtml()) {
            alert("Dữ liệu nhập không được có ký tự '<' ở đầu.");
        } else {
            ClickButton(0);
        }
    });

</script>
<div class="noidung-nhaponline">
    <div class="login-fields2">
        <p style="float: left; padding-right: 5px; vertical-align: top;">
            <img src="../Images/rt_arrow.gif">
        <p>Thông tin Thường trú:</p>
    </div>
    <div class="row row-online-table-head">
        <div class="col-md-3 widthlabelTinhHuyenXa">
            @Html.LabelFor(model => model.RST_BOOK_RELATION_ID, new { @class = "control-label " })
        </div>
        <div class="col-md-4 ">
            <div class="radio RST_BOOK_RELATION_ID" style="margin-top: 0%; margin-left: 5%;">

            </div>
        </div>

    </div>
    <div class="row row-online-table1">
        <div class="col-md-2 lbldai">
            @Html.LabelFor(m => m.ARRIVE_DATE, new { @class = "control-lable" })
        </div>
        <div class="col-md-4 controldai">
            @Html.TextBoxFor(model => model.DAYAR, new { @class = "form-control", style = "width: 25%; display: inline;", MaxLength = 2, @title = @Html.ToolTipMessageFor(m => m.DAYAR) })/@Html.TextBoxFor(model => model.MONTHAR, new { @class = "form-control", style = "width: 25%; display: inline;", MaxLength = 2, @title = @Html.ToolTipMessageFor(m => m.MONTHAR) })/@Html.TextBoxFor(model => model.YEARAR, new { @class = "form-control", style = "width: 35%; display: inline;", MaxLength = 4, @title = @Html.ToolTipMessageFor(m => m.YEARAR) })
        </div>
        <div class="col-md-2">
            @Html.LabelFor(m => m.RELIGION_ID, new { @class = "control-lable", style = "padding-left: 35%;" })
        </div>
        <div class="col-md-4">
            <select class="RELIGION_ID form-control " style="width:98%;"></select>
        </div>
    </div>
    <div class="row row-online-table1">
        <div class="col-md-3 lbldai">
            @Html.LabelFor(model => model.POBA_ADM_UNIT_ID, new { @class = "control-label " })
        </div>
        <div class="col-md-3 widthTinhHuyenXadai">
            @Html.DropDownList("TINH", ViewData["DISTRICT_CODE"] as List<SelectListItem>, new { @class = "form-control", @title = @Html.ToolTipMessageFor(m => m.TINH) })

        </div>
        <div class="col-md-3 widthTinhHuyenXadai">
            @Html.DropDownList("HUYEN", new SelectList(string.Empty, "Value", "Text"), new { @class = "form-control", @title = @Html.ToolTipMessageFor(m => m.HUYEN) })
        </div>
        <div class="col-md-3 widthTinhHuyenXadai">
            @Html.DropDownList("XA", new SelectList(string.Empty, "Value", "Text"), new { @class = "form-control", @title = @Html.ToolTipMessageFor(m => m.XA) })
        </div>
    </div>
    <div>
        @Html.HiddenFor(model => model.RESIDENT_ID)
        @Html.HiddenFor(model => model.HOUSEHOLD_ID)
        @Html.HiddenFor(model => model.CODEAR)
        @Html.HiddenFor(model => model.RELIGION_ID)
        @Html.HiddenFor(model => model.RST_BOOK_RELATION_ID)
    </div>
    <center>
        <input type="button" class="btn btn-small btn-small_online btn-success buttonClick " id="btnBack" value="<< Quay lại">
        <input type="button" class="btn btn-small btn-small_online btn-success buttonClick" id="btnNext" value="Tiếp tục >>">
    </center>
</div>
